package com.wlyuan.open.scanner.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.dto.OpenCombineQuotationSyncDTO;
import com.wlyuan.open.dto.transport.CombineQuotationSpecDTO;
import com.wlyuan.open.scanner.domain.quotation.CombineQuotation;
import com.wlyuan.open.scanner.domain.quotation.CombineQuotationSpec;
import com.wlyuan.open.scanner.utils.enums.quotation.QuotationMapping;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ScannerCombineQuotationAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {QuotationMapping.class, MappingIds.class})
    public interface Assembler {

        /**
         * 转换
         *
         * @param source
         * @return
         */
        @Mappings({
                @Mapping(source = "totalWeight", target = "calculateWeight"),
                @Mapping(source = "totalVolume", target = "calculateVolume"),
                @Mapping(source = "totalValue", target = "calculateValue"),

                @Mapping(source = "transportFee", target = "transportFee"),
                @Mapping(source = "pickCost", target = "pickFee"),
                @Mapping(source = "deliveryCost", target = "deliverFee"),
                @Mapping(source = "onLoadCost", target = "loadFee"),
                @Mapping(source = "offLoadCost", target = "unloadFee"),
                @Mapping(source = "minCost", target = "minimumFee"),
                @Mapping(source = "insuranceCost", target = "insureFee"),
                @Mapping(source = "taxCost", target = "taxFee"),
                @Mapping(source = "payment", target = "prepayFee"),
                @Mapping(source = "payable", target = "arrivePayFee"),
                @Mapping(source = "paysub", target = "collectionFee"),
                @Mapping(source = "additionCost", target = "surchargeFee"),

                @Mapping(source = "refresh", target = "recalculated"),
        })
        OpenCombineQuotationSyncDTO assemble(CombineQuotation source);

        @Mappings({
                @Mapping(source = "totalWeight", target = "calculateWeight"),
                @Mapping(source = "totalVolume", target = "calculateVolume"),
                @Mapping(source = "totalValue", target = "calculateValue"),
        })
        CombineQuotationSpecDTO assemble(CombineQuotationSpec source);

        @AfterMapping
        default void after(@MappingTarget OpenCombineQuotationSyncDTO target, CombineQuotation source) {

        }


        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<OpenCombineQuotationSyncDTO> assemble(List<CombineQuotation> source);

    }

    public static List<OpenCombineQuotationSyncDTO> assemble(List<CombineQuotation> creation) {
        return ASSEMBLER.assemble(creation);
    }

    public static OpenCombineQuotationSyncDTO assemble(CombineQuotation creation) {
        return ASSEMBLER.assemble(creation);
    }

}
